package com.dhcc.cdc.busi.controller;


import com.baomidou.mybatisplus.plugins.Page;
import com.dhcc.cdc.busi.entity.CdcLabSetEntity;
import com.dhcc.cdc.busi.service.ICdcLabSetService;
import com.dhcc.core.framework.annotion.BussinessLog;
import com.dhcc.core.framework.annotion.Permission;
import com.dhcc.core.framework.base.controller.BaseController;
import com.dhcc.core.framework.base.warpper.EmptyWarpper;
import com.dhcc.core.framework.exception.BizException;
import com.dhcc.core.framework.exception.BizExceptionEnum;
import com.dhcc.core.framework.result.R;
import com.dhcc.core.framework.result.page.PageFactory;
import com.dhcc.core.framework.util.CommonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;


/**
 * 检验组套
 * 
 * @ClassName: LabSetController
 * @Description: TODO
 * @author jumper
 * @date 2021-04-26 16:21:40
 */
@Controller
@RequestMapping("${sys.backendPath}/cdc/labset")
public class CdcLabSetController extends BaseController {

	private String PREFIX = "/backend/cdc/labset/";

	@Autowired
	private ICdcLabSetService labSetService;
	

    /**
     * 跳转到检验组套列表首页
     */
    @RequestMapping("")
    @Permission("labset:list")
    public String index() {
        return PREFIX + "labset.html";
    }
	
    /**
     * 跳转到新增检验组套
     */
    @RequestMapping("/to_add")
    @Permission("labset:add")
    public String toAdd() {
        return PREFIX + "labset_add.html";
    }
	
	/**
     * 跳转到修改检验组套
     */
    @RequestMapping("/to_update/{labSetId}")
    @Permission("labset:update")
    public String toUpdate(@PathVariable Long labSetId, Model model) {
        CdcLabSetEntity labSet = this.labSetService.selectById(labSetId);
        model.addAttribute("labSet",labSet);
        return PREFIX + "labset_edit.html";
    }

    /**
     * 获取检验组套列表
     */
	@SuppressWarnings("unchecked")
    @RequestMapping(value = "/list")
    @ResponseBody
    @Permission("labset:list")
    public Object list(@RequestParam Map<String, Object> params) {
		Page<CdcLabSetEntity> page = new PageFactory<CdcLabSetEntity>().defaultPage();
        List<CdcLabSetEntity> result = this.labSetService.page(page,params);
        page.setRecords((List<CdcLabSetEntity>) new EmptyWarpper(result).warp());
        return R.packForBT(page);
    }

    /**
     * 新增检验组套
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    @Permission("labset:add")
    @BussinessLog(value = "新增检验组套")
    public Object add(CdcLabSetEntity labSet) {
        if (CommonUtil.isOneEmpty(labSet)) {
            throw new BizException(BizExceptionEnum.REQUEST_NULL);
        }
        labSet.insert();
        return R.ok();
    }

    /**
     * 删除检验组套
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    @Permission("labset:delete")
    @BussinessLog(value = "删除检验组套")
    public Object delete(@RequestParam Long labSetId) {
	
        this.labSetService.deleteById(labSetId);

        return R.ok();
    }

    /**
     * 修改检验组套
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    @Permission("labset:update")
    @BussinessLog(value = "修改检验组套")
    public Object update(CdcLabSetEntity labSet) {
        if (CommonUtil.isOneEmpty(labSet)) {
            throw new BizException(BizExceptionEnum.REQUEST_NULL);
        }
        CdcLabSetEntity old = this.labSetService.selectById(labSet.getId());

        old.setLabVisitId(labSet.getLabVisitId());
        old.setOrderExecId(labSet.getOrderExecId());
        old.setCtLabOrderId(labSet.getCtLabOrderId());
        old.setIsActive(labSet.getIsActive());
        old.setMergeLabOrder(labSet.getMergeLabOrder());
        old.updateAllColumnById();
        return R.ok();
    }
	
}
